package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.entity.User;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * Author：汤小洋
 * Date：2025-07-29 16:39
 * Description：<描述>
 */
@RestController
@RequiredArgsConstructor
public class ProducerController {

    private final RabbitTemplate rabbitTemplate;

    @Value("${shop.exchange}")
    private String exchange;

    @Value("${shop.routingKey}")
    private String routingKey;

    @GetMapping("/send")
    public String send(){
        // rabbitTemplate.convertAndSend("exchange1.direct", "key1", "hello");
        // rabbitTemplate.convertAndSend(exchange, routingKey, new User(2, "alice", 18));

        rabbitTemplate.convertAndSend("exchange2.fanout", "", "Welcome to wanho");
        return "success";
    }

    @GetMapping("/send2")
    public String send2(){
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend("exchange1.direct", "key1", "111", correlationData);

        return "success";
    }


}
